<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Care extends MY_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->load->model('care_model');
    }

    public function index() {
        $param['repairid'] = $this->input->get_post('repairid');
        $param['repairname'] = $this->input->get_post('repairname');
        $param['start'] =  intval($this->input->get_post('per_page'));
        $param['length'] = 10;

        $data = $this->care_model->select_care_lise($param);

        $this->load->library('pagination');
        $config['base_url'] = site_url('c=care&m=index&repairid='.$param['repairid'].'&repairname='.$param['repairname']);
        $config['total_rows'] = $data['count'];
        $config['per_page'] = 10;
        $config['cur_tag_open'] = '<span class="page_now">';
        $config['cur_tag_close'] = '</span>';

        $this->pagination->initialize($config);
        $data['pagelink'] = $this->pagination->create_links();

        $this->common_header();
        $this->load->view("careList", $data);
        $this->common_footer();
    }

    public function add() {
        $this->form_validation->set_rules('repairname', '保养项目名称', 'required');
        $this->form_validation->set_rules('repairtime', '保养时间周期', 'required|numeric');
        $this->form_validation->set_rules('repairmileage', '保养行驶公里数周期', 'required|numeric');

        if($this->form_validation->run() === FALSE) {
            $data['faultInfo'] =  $this->care_model->select_care_fault_list();

            $this->common_header();
            $this->load->view("careAdd", $data);
            $this->common_footer();
        }else{
            $this->care_model->insert();
            $this->show_message("添加保养项目成功",site_url("c=care&m=index"));
        }
    }

    public function delete() {
        $this->care_model->delete();
        $this->show_message("删除保养项目信息成功",site_url("c=care&m=index"));
    }

    public function edit() {
        $this->form_validation->set_rules('repairname', '保养项目名称', 'required');
        $this->form_validation->set_rules('repairtime', '保养时间周期', 'required|numeric');
        $this->form_validation->set_rules('repairmileage', '保养行驶公里数周期', 'required|numeric');

        if($this->form_validation->run() === FALSE) {
            $data = $this->care_model->select_care_by_id();
            $data['faultInfo'] =  $this->care_model->select_care_fault_list();

            $this->common_header();
            $this->load->view("careEdit", $data);
            $this->common_footer();
        }else{
            $this->care_model->update();
            $this->show_message("修改保养项目成功",site_url("c=care&m=index"));
        }
    }
}